package com.songlanyun.modules.logisticscompany.service.impl;

import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.Query;
import com.songlanyun.modules.logisticscompany.dao.SystemLogisticsCompanyDao;
import com.songlanyun.modules.logisticscompany.entity.SystemLogisticsCompanyEntity;
import com.songlanyun.modules.logisticscompany.service.SystemLogisticsCompanyService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("yxtSystemLogisticsCompanyService")
public class SystemLogisticsCompanyServiceImpl extends ServiceImpl<SystemLogisticsCompanyDao, SystemLogisticsCompanyEntity> implements SystemLogisticsCompanyService {

    /**
     * 列表
     *
     * @param params
     * @return
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String company = MapUtil.getStr(params, "company");//物流名称
        String logisticsCode = MapUtil.getStr(params, "logistics_code");//物流名称

        IPage<SystemLogisticsCompanyEntity> page = this.page(
                new Query<SystemLogisticsCompanyEntity>().getPage(params),
                new LambdaQueryWrapper<SystemLogisticsCompanyEntity>()
                        .like(StringUtils.isNotBlank(company), SystemLogisticsCompanyEntity::getCompany, company)
                        .like(StringUtils.isNotBlank(company), SystemLogisticsCompanyEntity::getLogisticsCode, logisticsCode)
                        .orderByAsc(SystemLogisticsCompanyEntity::getOrderIndex)
        );

        return new PageUtils(page);
    }

    @Override
    public SystemLogisticsCompanyEntity loadByName(String name) {
        return this.getOne(new LambdaQueryWrapper<SystemLogisticsCompanyEntity>().eq(SystemLogisticsCompanyEntity::getCompany, name).last("limit 1"));

    }
}
